﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YBApproval.IDAL;
using YBApproval.BLL;
using YBApproval.Model;
using System.Text;

namespace YBApproval.Pages
{
    public partial class Services : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["Action"] == "GetUsers")
            {
                GetUsers();
            }
            else if (Request.QueryString["Action"] == "GetRoles")
            {
                GetRoles();
            }
        }

        private void GetUsers()
        {
            IUserProfile userDAL = DALFactory.GetDAL<IUserProfile>();
            List<UserProfile> list = userDAL.GetAll();
            StringBuilder builder = new StringBuilder();
            foreach (UserProfile user in list)
            {
                builder.Append("<option value='" + user.Id + "'>" + user.Name + "</option>");
            }
            Response.Write(builder.ToString());
        }

        private void GetRoles()
        {
            IRole roleDAL = DALFactory.GetDAL<IRole>();
            List<Role> list = roleDAL.GetAll();
            //TODO: Can change to get roles from session.
            //List<Role> list = YBPSession.Instance.AllRolesList;
            StringBuilder builder = new StringBuilder();
            foreach (Role role in list)
            {
                builder.Append("<option value='" + role.Id + "'>" + role.Name + "</option>");
            }
            Response.Write(builder.ToString());
        }
    }
}